﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPay.Infrastructure.Unity;

namespace Utility
{
    public class SelectListItemHelper
    {
        public static dynamic GetListByT(IEnumerable<SelectListItem> list, bool shoowEmpty=true, string text = "-请选择-")
        {
            var result = new List<SelectListItem>();
            if (shoowEmpty)
            {
                result.Add(new SelectListItem() { Text = text, Value = "" });
            }
            if (list != null && list.Any())
            {
                list.ToList().ForEach(x =>
                {
                    result.Add(new SelectListItem() { Text = x.Text, Value = x.Value, Selected = x.Selected });
                });
            }
            return result;
        }

        public static string LoadBitOption(bool? val = null, bool IsEmpty = false)
        {
            return (IsEmpty ? "<option value=\"\">--全部--</option>" : "") +
                   "<option  value=\"false\">否</option><option " + (val != null ? val.Value ? "selected=\"selected\"" : "" : "") + " value=\"true\">是</option>";
        }
    }
}
